const pageMixin = {
  data () {
    return {
      listMode: true,
      ids: [],
      ckAll: false,
      searchStr: '',
      total: 0,
      page: 1,
      pageSize: 30,
      list: []
    }
  },
  methods: {
    handleChangeMode (listMode) {
      this.listMode = listMode
      this.pageSize = this.listMode ? 10 : 8
    },
    onPageChange (p) {
      this.page = p.page
      this.pageSize = p.pageSize
      this.search()
    },
    handleSearch (searchStr) {
      this.searchStr = searchStr
      this.search()
    },
    search () {
    },
    getList () {
      return JSON.parse(JSON.stringify(this.list))
    },
    checkIds (callback, confirmInfo) {
      if (this.ids.length === 0) {
        this.$warning({ title: '请选择要操作的数据' })
        return
      }
      this.confirm(() => {
        callback(this.ids)
      }, confirmInfo || '确定要删除这些数据么')
    },
    ckAllChange (e) {
      this.list.forEach(t => {
        t.ck = e.target.checked
      })
    },
    ckChange () {
      this.ckAll = this.list.every(t => {
        return t.ck
      })
    },

    // 按钮数据解析组装
    operatesArr (btnObj) {
      const arr = []
      for (const i in btnObj) {
        console.log('btnObj[i]', btnObj[i])
        btnObj[i].map(item => {
          arr.push({ name: item.name, code: item.code })
        })
      }
      return arr
    },
    // 过滤条件解析组装
    setCondition (data) {
      const arr = []
      data.map((item, index) => {
        const obj = {
          name: item.label,
          code: item.code,
          type: item.compType
        }
        switch (item.compType) {
          case '下拉选择':
            obj.list = item.extra['下拉选项']
            break
          case '日期区间':
            obj[item.code + '_s'] = ''
            obj[item.code + '_e'] = ''
            break
          case '整数区间':
            obj[item.code + '_s'] = ''
            obj[item.code + '_e'] = ''
            break
          case '字典':
            obj.list = []
            break
          case '布尔':
            obj.list = [{ value: 'true', label: '是' }, { value: 'false', label: '否' }]
            break
          case '单选':
            obj.list = item.extra['选项']
        }
        arr.push(obj)
      })
      return arr
    }

  }
}

export {
  pageMixin
}
